package com.demo.mapreduce;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class EventCountDemo {
	public static void execute(String inputPath, String outputPath)
			throws Exception {
		Configuration conf = new Configuration();
		Job job = Job.getInstance(conf, "event count");
		job.setJarByClass(EventCountDemo.class);
		job.setMapperClass(MyMapper.class);
		job.setCombinerClass(MyReducer.class);
		job.setReducerClass(MyReducer.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		FileInputFormat.addInputPath(job, new Path(inputPath));
		FileOutputFormat.setOutputPath(job, new Path(outputPath));
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}

	public static void main(String[] args) {
		try {
			execute("/user/hadoop", "/user/hadoop/output");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
